From 8ac426320eee9727a3c9e0046af40e103f4e1c34 Mon Sep 17 00:00:00 2001 From: oliskoli Date: Sun, 13 Aug 2006 17:15:00 +0000 Subject: [PATCH] Merge fixes from 'zlib/gzio.c' and replace 'zlib/gzio.c' with original version. --- gbfile.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/gbfile.c b/gbfile.c index f78ce5f3d..30283d96e 100644 --- a/gbfile.c +++ b/gbfile.c @@ -61,7 +61,9 @@ gbfopen(const char *filename, const char *mode, const char *module) switch(tolower(*m)) { case 'r': file->mode = 'r'; - file->gzapi = 1; +#if !ZLIB_INHIBITED + file->gzapi = 1; /* native or transparent */ +#endif break; case 'w': file->mode = 'w'; @@ -78,7 +80,25 @@ gbfopen(const char *filename, const char *mode, const char *module) if (file->gzapi) { #if !ZLIB_INHIBITED - file->handle.gz = gzopen(filename, mode); + char openmode[32]; + + /* under non-posix systems files MUST be opened in binary mode */ + + strcpy(openmode, mode); + if (strchr(mode, 'b') == NULL) + strncat(openmode, "b", sizeof(openmode)); + + if (strcmp(filename, "-") == 0) { + FILE *fd; + if (file->mode == 'r') + fd = stdin; + else + fd = stdout; + file->handle.gz = gzdopen(fileno(fd), openmode); + } + else + file->handle.gz = gzopen(filename, openmode); + if (file->handle.gz == NULL) { fatal("%s: Cannot %s file '%s'!\n", module, @@ -88,7 +108,7 @@ gbfopen(const char *filename, const char *mode, const char *module) file->gzapi = 1; #else /* This is the only runtime test we make */ - fatal("Zlib was not included in this build."); + fatal("%s: Zlib was not included in this build.\n", file->module); #endif } else { -- 2.30.2